package com.family.gmall.common.retryer;

import feign.RetryableException;
import feign.Retryer;

/**
 * @Auther: family
 * @Date: 2023/7/20 16:15
 * @Description:
 */
public class Retryer3 implements Retryer {

    int count = 3;
    int num = 0;

    /**
     * 远程超市feign会自动调用这个方法
     * 1. Propagate：传播错误
     * 2. 重试器的方法只要不抛出错误就会继续重试一次远程调用
     *
     * @param e
     */
    @Override
    public void continueOrPropagate(RetryableException e) {
        if (num++ >= count) {
            throw e;
        }
    }

    @Override
    public Retryer clone() {
        return new Retryer3();
    }
}
